<template>
  <div class="maincontainer">
    <el-container>
      <!-- 绑定属性看是否展示 -->
      <el-aside width="200px" :width="isCollapse ? '60px' : '200px'">
        <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
          <el-radio-button :label="false">展开</el-radio-button>
          <el-radio-button :label="true">收起</el-radio-button>
        </el-radio-group>
        <el-menu
          default-active="1-4-1"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="isCollapse"
          :router="true"
          background-color="#272c33"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
         <Menu :menuData="menuData"></Menu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="avater">
            <img src="../../assets/images/c.jpg" />
          </div>
          <span>欢迎来到超哥女闺蜜管理系统</span>
          <div class="avaterlogout">
            <img src="../../assets/images/QQ图片20230215111336.gif" />
            <el-row class="block-col-2">
              <el-col :span="24">
                <el-dropdown class="user">
                  <span class="el-dropdown-link">
                    用户中心<i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item icon="el-icon-plus"
                      >账户中心</el-dropdown-item
                    >
                    <el-dropdown-item icon="el-icon-circle-plus"
                      >论坛</el-dropdown-item
                    >
                    <!-- 原生点击退出 -->
                    <el-dropdown-item
                      @click.native="logout"
                      icon="el-icon-circle-plus-outline"
                      >注销</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </el-col>
            </el-row>
          </div>
        </el-header>
        <el-main>
        <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
import { USERLOGIN, USERLOGOUT } from "../../store/types";
import {findMenuTree} from '../../api/menu'
import Menu from '../../components/Menu.vue'
export default {
  //局部组件
  components:{
    Menu
  }
  ,
  data() {
    return {
      isCollapse: false, //卷闸门 收缩与展开
      menuData:[]//树菜单集合
    };
  },
  methods: {
    ...mapMutations([USERLOGIN, USERLOGOUT]),
    async getMenuTree(){
     let res=   await findMenuTree();
     console.log(res);
     this.menuData= res.data.menutree;
    },
    logout() {
      if (confirm("那我走？我真的走了，哎。。。")) {
        //路由导航推送
        this[USERLOGOUT]();
        this.$router.push({
          path: "/",
        });
      }
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
  created(){
    this.getMenuTree();
  }
};
</script>

<style lang="less" scoped>
 .el-menu{
  background-color: #333;
 }
.el-header {
  display: flex;
  justify-content: space-between;
}
img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.demonstration {
  display: block;
  color: #8492a6;
  font-size: 14px;
  margin-bottom: 20px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #333;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-header {
  background-color: #333;
}
span {
  color: white;
  font-size: 30px;
}
.user {
  font-size: 12px;
}
.avaterlogout {
  display: flex;
  justify-content: space-between;
}

</style>
